

// Sets up callbacks for state change
// You should not set up the state object until you get your first callback.
function init() {
   console.log("init");
   gapi.hangout.data.addStateChangeListener(pianoUpdated);
   
   gapi.hangout.addParticipantsListener(participantsUpdated);
}



function pianoUpdated(delta, metadata){
	if(gapi.hangout.data.getState()['piano']) {	     
		var note = gapi.hangout.data.getState()['piano'];
		
		console.log("piano Updated" + note );
		
		playKey(note.split("_")[0], note.split("_")[1]);
		resetPiano();
		
	}else{
		console.log("piano undefined");
	}
}


function addPiano(src){
  	console.log("Button clicked addPiano");
   	console.log( gapi.hangout.data.getState()['piano'] );


	var id = gapi.hangout.getParticipantId();
	var name = gapi.hangout.getParticipantById(id).displayName;


	gapi.hangout.data.submitDelta({'piano': src});
}



// Note that the hangouts object is not set up until the gadget loads
gadgets.util.registerOnLoadHandler(init);
       
// Reset value of "count" to 0
function resetPiano(){      
	console.log("reset Piano");
	gapi.hangout.data.submitDelta({'piano': ''});
}
